package com.gxa.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gxa.common.R;
import com.gxa.entity.DistrictSysContatanalysis;
import com.gxa.mapper.CloseContactAnalysisMapper;
import com.gxa.service.CloseContactAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CloseContactAnalysisServiceImpl implements CloseContactAnalysisService {
    @Autowired
    private CloseContactAnalysisMapper closeContactAnalysisMapper;
    @Override

    /**
     * 分页查询密接人群分析表
     * @param currentPage
     * @return
     */
    public R findCloseContactAnalysis(Integer currentPage) {
        R r = new R();
        Date currentDate = new Date();
        DistrictSysContatanalysis districtSysContatanalysis = new DistrictSysContatanalysis();
        districtSysContatanalysis.setDate(currentDate);
        districtSysContatanalysis.setContactNum(closeContactAnalysisMapper.findTodayContactNum(currentDate));
        districtSysContatanalysis.setVerificationNum(closeContactAnalysisMapper.findTodayVerificationNum(currentDate));
        districtSysContatanalysis.setMedicalObservation(closeContactAnalysisMapper.findTodayObservationNum(currentDate));
        districtSysContatanalysis.setTransferNum(closeContactAnalysisMapper.findTodayTransferNum(currentDate));
        districtSysContatanalysis.setTroubleshootingNum(closeContactAnalysisMapper.findTodayTroubleshootingNum(currentDate));
        districtSysContatanalysis.setReceiveNum(closeContactAnalysisMapper.findTodayReceiveNum(currentDate));
        districtSysContatanalysis.setIsolationNum(closeContactAnalysisMapper.findTodayIsolationNum(currentDate));
        districtSysContatanalysis.setHomeNum(closeContactAnalysisMapper.findTodayHomeNum(currentDate));
        districtSysContatanalysis.setRemovalNum(closeContactAnalysisMapper.findTodayRemovalNum(currentDate));

        int row =closeContactAnalysisMapper.addTodayCloseContactAnalysis(districtSysContatanalysis);
        if (row > 0){
            Page page = PageHelper.startPage(currentPage,10);
            List<DistrictSysContatanalysis> districtSysContatanalysisList = closeContactAnalysisMapper.findCloseContactAnalysisList();
            int total = (int)page.getTotal();
            Map map = new HashMap();
            map.put("total",total);
            map.put("districtSysContatanalysisList",districtSysContatanalysisList);
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(map);

        }else {
            r.setCode(400);
            r.setMsg("查询失败");
        }
        return r;
    }


    /**
     * 根据日期查询密接人群分析表
     * @param currentPage
     * @param currentDate
     * @return
     */
    @Override
    public R findCloseContactAnalysisByDate(Integer currentPage, Date currentDate) {
        R r = new R();
        Page page = PageHelper.startPage(currentPage,10);
        List<DistrictSysContatanalysis> districtSysContatanalysisList = closeContactAnalysisMapper.findCloseContactAnalysisListByDate(currentDate);
        int total = (int)page.getTotal();
        Map map = new HashMap();
        map.put("total",total);
        map.put("districtSysContatanalysisList",districtSysContatanalysisList);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(map);
        return r;
    }
}
